//
//  VideoDetailViewController.m
//  MeiShiDa
//
//  Created by duanshiyi on 15/7/4.
//  Copyright (c) 2015年 zby. All rights reserved.
//

#import "VideoDetailViewController.h"
#import "KrVideoPlayerController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface VideoDetailViewController ()
@property (nonatomic, strong) KrVideoPlayerController *Video;
@end

@implementation VideoDetailViewController




- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title=_titleStr;
    self.view.backgroundColor=[UIColor whiteColor];
    
    
    [self addVideoPlayerWithURL:[NSURL URLWithString:_passURLStr]];

//    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:<#(NSURL *)#>]
}


//创建播放器  控制播放器
- (void)addVideoPlayerWithURL:(NSURL *)url{

    
    if (!self.Video) {
        CGFloat width = [UIScreen mainScreen].bounds.size.width;
        self.Video = [[KrVideoPlayerController alloc] initWithFrame:CGRectMake(0, 64, width, width*(9.0/16.0))];
        //创建block匿名函数之前一般需要对self进行weak化    否则造成循环引用无法释放Controller
        __weak typeof(self)weakSelf = self;
        __block VideoDetailViewController *videoVC=self;
        [self.Video setDimissCompleteBlock:^{
            [weakSelf.Video dismiss];
            weakSelf.Video = nil;
            [videoVC.navigationController popToRootViewControllerAnimated:YES];
        }];
        
        //非全屏状态不隐藏  导航栏
        [self.Video setWillBackOrientationPortrait:^{
            [weakSelf toolbarHidden:NO];
            
        }];
        
        //全屏状态隐藏状态栏
        [self.Video setWillChangeToFullscreenMode:^{
            [weakSelf toolbarHidden:YES];
        }];
        
        [self.view addSubview:self.Video.view];
        
    }
    
    self.Video.contentURL = url;
}


//隐藏导航栏
- (void)toolbarHidden:(BOOL)Bool{
    //隐藏导航栏
    self.navigationController.navigationBar.hidden = Bool;
    //隐藏tabBar
    self.tabBarController.tabBar.hidden = Bool;
    [[UIApplication sharedApplication] setStatusBarHidden:Bool withAnimation:UIStatusBarAnimationFade];
    
}



-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [self.Video dismiss];
    self.Video=nil;
}



@end
